﻿// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "openssl/rsa.h"
#include "openssl/pem.h"
#include "openssl/bn.h"
#include "openssl/bio.h"
#include "openssl/evp.h"
#include "openssl/ssl.h"
#include "openssl/err.h"

#include <QObject>

class RsaHelper : public QObject
{
    Q_OBJECT
public:
    enum KeyType {
        L1024,                          // 1024位密钥
        L2048,                          // t2048位密钥
    };

    explicit RsaHelper(QObject *parent = nullptr);
    ~RsaHelper();

    void setKeyType(KeyType type);
    void setPublicKey(const QString &key);
    void setPrivateKey(const QString &key);
    QString encrypt(const QString &data);
    QString decrypt(const QString &data);

private:
    KeyType m_keyType;
    BIO *m_publicKeyBio;
    RSA *m_publicKeyRsa;
    BIO *m_privateKeyBio;
    RSA *m_privateKeyRsa;

};
